package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

/**
 * createTime：2021/8/23 17:55
 * description：SynchronizedConstructor
 */

class SyncConstructor implements HasID {
    private final int id;

    private static Object constructorLock = new Object();

    SyncConstructor(ShareArg sa) {
        synchronized (constructorLock) {
            id = sa.get();
        }
    }

    @Override
    public int getID() {
        return id;
    }
}

public class SynchronizedConstructor {
    public static void main(String[] args) {
        UnSafe unSafe = new UnSafe();
        IDChecker.test(() -> new SyncConstructor(unSafe));
    }
}
